package com.zqc.service.impl;

import com.zqc.service.ServiceInterface;
import org.apache.dubbo.config.annotation.Service;

import java.util.Random;

/**
 * 接口实现类
 */
@Service
public class ServiceInterfaceImpl implements ServiceInterface {
    @Override
    public String methodA() {
        System.out.println("Method A");

        // 随机睡眠0~100ms
        sleep();

        return "success method A";
    }

    @Override
    public String methodB() {
        System.out.println("Method B");

        // 随机睡眠0~100ms
        sleep();

        return "success method B";
    }

    @Override
    public String methodC() {
        System.out.println("Method C");

        // 随机睡眠0~100ms
        sleep();

        return "success method C";
    }

    /**
     * 随机睡眠0~100ms
     */
    private void sleep() {
        Random random = new Random();
        int randomNumber = random.nextInt(101);
        try {
            System.out.println("睡眠了" + randomNumber + "毫秒");
            Thread.sleep(randomNumber);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
